import axios from "axios";

//提取公共的基路径
const instance = axios.create({
  baseURL: "http://47.122.115.10:5000", //请求的基路径
  // baseURL: "/api", //请求的基路径
  timeout: 5000, //请求超时时间
});

//拦截器拦截请求和响应
instance.interceptors.request.use(
  (config) => {
    const token = JSON.parse(localStorage.getItem("t_k") as string);
    if (token) {
      config.headers.Authorization = token;
    }
    return config;
  },
  (err) => {
    console.log(err);
  }
);

instance.interceptors.response.use(
  (response) => {
    return response;
  },
  (err) => {
    console.log(err);
  }
);

const get = async (url: string) => {
  return instance.get(url);
};
export default {
  get,
};
